/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        ListNode* newhead = new ListNode(-1);
        newhead->next = head;
        ListNode* slow = newhead;
        ListNode* fast = head;
        while (fast && n--)
        {
            fast = fast->next;
        }
        if (fast == nullptr) head = head->next;
        while (fast)
        {
            slow = slow->next;
            fast = fast->next;
        }
        slow->next = slow->next->next;
        delete newhead;
        return head;
    }
};

class Solution {
public:
    bool checkInclusion(string s1, string s2) {
        int hash1[128] = { 0 };
        int hash2[128] = { 0 };
        for (char ch : s1) hash1[ch]++;
        int n = s2.size();
        int m = s1.size();
        for (int left = 0, right = 0; right < n; right++)
        {
            hash2[s2[right]]++;
            while (hash2[s2[right]] > hash1[s2[right]])
                hash2[s2[left++]]--;
            if (right - left + 1 == m)
                return true;
        }
        return false;
    }
};